package com.enzi.webclient.controller;

import com.enzi.webclient.IUserApi;
import com.enzi.webclient.domian.User;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @Author: enzi.cheng
 * @Date: 2019/1/15 09:19
 * @Description:
 */
@AllArgsConstructor
@RestController
public class TestController {

    private final IUserApi userApi;

    @GetMapping("/")
    public void test(){
        Flux<User> allUser = userApi.getAllUser();
        allUser.subscribe(user -> {
            System.out.println("getUserById:"+ user);
        });
       userApi.getUserById("5c3de438d273a9056be5f491").subscribe(user -> {
           System.out.println("getUserById:"+ user);
       });
      userApi.createUser(Mono.just(User.builder().age(44).name("tttttt").build())).subscribe(user -> {
          System.out.println("getUserById:"+ user);
      });
       userApi.deleteUserById("5c3de438d273a9056be5f491").subscribe(user -> {
           System.out.println("getUserById:"+ user);
       });
        userApi.updateUser("5c3de438d273a9056be5f491", Mono.just(User.builder().age(43).name("yyyy").build())).subscribe(user -> {
            System.out.println("getUserById:"+ user);
        });

        IUserApi userApi1 = userApi;
        userApi.getUserByRequestParam("5c3de438d273a9056be5f491").subscribe(user -> {
            System.out.println("getUserById:" + user);
        });
    }


    @GetMapping("/t")
    public void test1(){
                IUserApi userApi1 = userApi;
        userApi.getUserByRequestParam("5c3de438d273a9056be5f491").subscribe(user -> {
            System.out.println("getUserById:" + user);
        });
    }
}
